home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic 4 Database How-To / Visual Basic 4 Database - How-to (The Waite Group)(1995).iso / errhand.fr_ / errhand.fr
Text File  |  1995-07-19  |  4KB  |  153 lines

  1. VERSION 4.00
  2. Begin VB.Form frmODBC 
  3.    BackColor       =   &H00C0C0C0&
  4.    Caption         =   "ODBC Errors"
  5.    ClientHeight    =   3210
  6.    ClientLeft      =   2325
  7.    ClientTop       =   2160
  8.    ClientWidth     =   2880
  9.    Height          =   3705
  10.    Left            =   2220
  11.    LinkTopic       =   "Form1"
  12.    ScaleHeight     =   3210
  13.    ScaleWidth      =   2880
  14.    Top             =   1770
  15.    Width           =   3090
  16.    Begin VB.CommandButton cmdQuit 
  17.       Caption         =   "&Quit"
  18.       Height          =   495
  19.       Left            =   480
  20.       TabIndex        =   3
  21.       Top             =   2400
  22.       Width           =   1935
  23.    End
  24.    Begin VB.CommandButton cmdAllochDbc 
  25.       Caption         =   "&Allocate hDbc"
  26.       Height          =   495
  27.       Left            =   480
  28.       TabIndex        =   1
  29.       Top             =   960
  30.       Width           =   1935
  31.    End
  32.    Begin VB.CommandButton cmdGetFunctions 
  33.       Caption         =   "&Get Functions"
  34.       Height          =   495
  35.       Left            =   480
  36.       TabIndex        =   2
  37.       Top             =   1560
  38.       Width           =   1935
  39.    End
  40.    Begin VB.CommandButton cmdDriverConnect 
  41.       Caption         =   "&Driver Connect"
  42.       Height          =   495
  43.       Left            =   480
  44.       TabIndex        =   0
  45.       Top             =   360
  46.       Width           =   1935
  47.    End
  48. End
  49. Attribute VB_Name = "frmODBC"
  50. Attribute VB_Creatable = False
  51. Attribute VB_Exposed = False
  52. Option Explicit
  53.  
  54. Private Sub cmdAllochDbc_Click()
  55.     Dim result As Integer
  56.     
  57.     'Problem: ghEnv is passed as a null handle
  58.     result = SQLAllocConnect(0, ghDbc)
  59.     If result <> SQL_SUCCESS Then
  60.         result = ODBCError("Dbc", 0, ghDbc, 0, result, "Error allocating connection handle.")
  61.         frmODBC.Show
  62.         Exit Sub
  63.     End If
  64. End Sub
  65.  
  66.  
  67. Private Sub cmdDriverConnect_Click()
  68.     Dim result As Integer
  69.     Dim connStrIn As String
  70.     Dim connStrOut As String * SQL_MAX_OPTION_STRING_LENGTH
  71.     #If Win32 Then
  72.         Dim strOutCount As Long
  73.     #Else
  74.         Dim strOutCount As Integer
  75.     #End If
  76.     
  77.     connStrIn = ""
  78.     
  79.     'Problems: Connect string is empty and function is told
  80.     'not to prompt for missing information
  81.     result = SQLDriverConnect(ghDbc, Me.hWnd, connStrIn, Len(connStrIn), connStrOut, Len(connStrOut), strOutCount, SQL_DRIVER_NOPROMPT)
  82.  
  83.     If result <> SQL_SUCCESS Then
  84.         result = ODBCError("Dbc", ghEnv, ghDbc, 0, result, "Problem with call to SQLDriverConnect.")
  85.         Exit Sub
  86.     End If
  87.     
  88.     'Free the connection, but not the handle
  89.     result = SQLDisconnect(ghDbc)
  90.     If result <> SQL_SUCCESS Then
  91.         result = ODBCError("Dbc", ghEnv, ghDbc, 0, result, "Problem with call to SQLDriverConnect.")
  92.     End If
  93. End Sub
  94.  
  95. Private Sub cmdGetFunctions_Click()
  96.     Dim result As Integer
  97.     Dim FuncList(100) As Integer
  98.     
  99.     'Problem: second argument requests information about a
  100.     'particular function or all functions. The number must
  101.     'be positive.
  102.     result = SQLGetFunctions(ghDbc, -5, FuncList(0))
  103.     If result <> SQL_SUCCESS Then
  104.         result = ODBCError("Dbc", ghEnv, ghDbc, 0, result, "Error getting list of ODBC functions")
  105.         Screen.MousePointer = DEFAULT
  106.         Exit Sub
  107.     End If
  108.  
  109. End Sub
  110.  
  111. Private Sub cmdQuit_Click()
  112.     End
  113. End Sub
  114.  
  115.  
  116. Private Sub Form_Load()
  117.     'Log on to an ODBC data source
  118.     'First, allocate ODBC memory and get handles
  119.     Dim result As Integer
  120.     Dim fHeight As Integer, fWidth As Integer
  121.     Dim fTop As Integer, fLeft As Integer
  122.     
  123.     'Resize and center the form
  124.     fLeft = (Screen.Width - frmODBC.Width) / 2
  125.     fTop = (Screen.Height - frmODBC.Height) / 2
  126.     
  127.     frmODBC.Move fLeft, fTop
  128.      
  129.     'Allocate the ODBC environment handle
  130.     result = ODBCAllocateEnv(ghEnv)
  131.     If result <> SQL_SUCCESS Then
  132.         End
  133.     End If
  134.     
  135.     result = SQLAllocConnect(ghEnv, ghDbc)
  136.     If result <> SQL_SUCCESS Then
  137.         result = ODBCError("Dbc", ghEnv, ghDbc, 0, result, "Error allocating connection handle.")
  138.         End
  139.     End If
  140.  
  141.     frmODBC.Show
  142.  
  143. End Sub
  144.  
  145. Private Sub Form_Unload(Cancel As Integer)
  146.     Dim result As Integer
  147.     
  148.     result = ODBCDisconnectDS(ghEnv, ghDbc, ghStmt)
  149.     result = ODBCFreeEnv(ghEnv)
  150.  
  151. End Sub
  152.  
  153.